<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>展位模板</span>
      </div>
      <div class="list-search">
        <el-select
          v-model="status"
          placeholder="可用状态"
          class="list-options"
          @change="funSearch"
        >
          <el-option label="不限状态" value="" />
          <el-option label="可用" value="1" />
          <el-option label="不可用" value="2" />
        </el-select>
        <el-input
          v-model="keyword"
          placeholder="请输入搜索内容"
          class="input-with-select"
          @keyup.enter.native="funSearchKeyword"
        >
          <el-select
            slot="prepend"
            v-model="key_type"
            placeholder="请选择"
            class="input-sel"
          >
            <el-option label="模板名称" value="1" />
          </el-select>
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="funSearchKeyword"
          />
        </el-input>
      </div>
      <div class="spaceline" />
      <el-table
        v-loading="listLoading"
        :data="list"
        element-loading-text="Loading"
        fit
        highlight-current-row
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="42" />
        <el-table-column label="模板名称" show-overflow-tooltip width="350">
          <template slot-scope="scope">
            {{ scope.row.title }}
          </template>
        </el-table-column>
        <el-table-column label="可用状态" align="center">
          <template slot-scope="scope">
            <el-tag :type="scope.row.status==1?'success':'info'">
              {{ scope.row.status==1?'可用':'不可用' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column align="right" label="操作" width="150">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              @click="funEdit(scope.$index, scope.row)"
            >
              修改
            </el-button>
            <el-button
              size="mini"
              type="danger"
              @click="funDelete(scope.$index, scope.row)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="spaceline" />
      <el-row :gutter="20">
        <el-col :span="8">
          <el-button size="small" type="primary" @click="goAdd">
            新增
          </el-button>
          <el-button size="small" type="danger" @click="funDeleteSelect">
            删除所选
          </el-button>
        </el-col>
        <el-col :span="16" style="text-align: right;">
          <el-pagination
            background
            :current-page="currentPage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>
<script>
import { positionTplList, positionTplDelete } from '@/api/jobfair'
export default {
  data() {
    return {
      status: '',
      keyword: '',
      key_type: '1',
      total: 0,
      currentPage: 1,
      pagesize: 10,
      listLoading: !1,
      list: [],
      tableIdarr: []
    }
  },
  created(){
    this.getPosition()
  },
  methods: {
    getPosition: function(){
      this.listLoading = true
      const param = {
        status: this.status,
        key_type: this.key_type,
        keyword: this.keyword,
        page: this.currentPage,
        pagesize: this.pagesize
      }
      positionTplList(param).then(response => {
        this.list = response.data.items
        this.listLoading = false
        this.total = response.data.total
        this.currentPage = response.data.current_page
        this.pagesize = response.data.pagesize
      })
    },
    funSearch: function(){
      this.getPosition()
    },
    funSearchKeyword: function(){
      this.currentPage = 1
      this.getPosition()
    },
    handleSizeChange: function(val){
      this.pagesize = val
      this.getPosition()
    },
    handleCurrentChange: function(val){
      this.currentPage = val
      this.getPosition()
    },
    handleSelectionChange(idlist) {
      this.tableIdarr = []
      if (idlist.length > 0) {
        for (const item of idlist) {
          this.tableIdarr.push(item.id)
        }
      }
    },
    funEdit: function(index, row){
      this.$router.push({
        path: '/jobfair/positionTpl/edit',
        query: {
          id: row.id
        }
      })
    },
    goAdd: function(){
      this.$router.push('/jobfair/positionTpl/add')
    },
    funDelete: function(index, row){
      var that = this
      that
        .$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          const param = {
            id: row.id
          }
          positionTplDelete(param).then(response => {
            that.$message.success(response.message)
            that.getPosition()
            return true
          })
        })
        .catch(() => {})
    },
    funDeleteSelect: function(){
      var that = this
      if (that.tableIdarr.length == 0) {
        that.$message.error('请选择要删除的数据')
        return false
      }
      that
        .$confirm('此操作将永久删除选中的数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          const param = {
            id: that.tableIdarr
          }
          positionTplDelete(param).then(response => {
            that.$message.success(response.message)
            that.getPosition()
            return true
          })
        })
        .catch(() => {})
    }
  }
}
</script>
<style lang="scss" scoped>
  .qrcode{vertical-align:middle}
</style>
